﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace _09_01动画基础
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, RoutedEventArgs e)
		{
			//创建一个双精度的动画
			DoubleAnimation doubleAnimation	=new DoubleAnimation();
			doubleAnimation.From = button1.Width; //设置动画的起始值
			doubleAnimation.To = button1.Height + 150; //设置动画的结束值
			doubleAnimation.Duration=TimeSpan.FromSeconds(1); //设置动画的持续时间
			doubleAnimation.AutoReverse= true; //是否自动返回
			//doubleAnimation.RepeatBehavior = RepeatBehavior.Forever; //执行次数
			doubleAnimation.RepeatBehavior = new RepeatBehavior(3); //执行次数

			doubleAnimation.Completed += DoubleAnimation_Completed;
			//在当前按钮上执行动画
			button1.BeginAnimation(Button.WidthProperty, doubleAnimation);
		}

		private void DoubleAnimation_Completed(object sender, EventArgs e)
		{
			button1.Content= "动画完成";
		}

	}
}
